// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
// vex-table
// import styleImport from 'vite-plugin-style-import'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 8088,
  },
  // 部署 pages 的 path
  base: '/hf-ui/',
  // 解决 "@charset" must be the first rule 的r报警
  css: {
    postcss: {
      plugins: [
        {
          postcssPlugin: 'internal:charset-removal',
          AtRule: {
            charset: (atRule) => {
              if (atRule.name === 'charset') {
                atRule.remove();
              }
            }
          }
        }
      ]
    },
    preprocessorOptions: {
      scss: {
        charset: false
      }
    }
  },
  plugins: [
    vue(),
    Components({
      dts: true, // 支持 ts enabled by default if `typescript` is installed
      // resolvers: [ElementPlusResolver()], // 支持 element plus run dev时报错疑似ts检查的原因
    }),
    // AutoImport({ /* options */ }),
    AutoImport({
      resolvers: [ElementPlusResolver()], // 支持 element plus
      imports: [
        'vue',
        'vue-router',
        // custom
        {
          '@vueuse/core': [
            // named imports
            'useMouse', // import { useMouse } from '@vueuse/core',
            // alias
            ['useFetch', 'useMyFetch'], // import { useFetch as useMyFetch } from '@vueuse/core',
          ],
          axios: [
            // default imports
            ['default', 'axios'], // import { default as axios } from 'axios',
          ],
          '[package-name]': [
            '[import-names]',
            // alias
            ['[from]', '[alias]'],
          ],
        },
      ],
    }),
    // vxe-table
    // styleImport({
    //   libs: [
    //     {
    //       libraryName: 'vxe-table',
    //       esModule: true,
    //       resolveComponent: name => `vxe-table/es/${name}`,
    //       resolveStyle: name => `vxe-table/es/${name}/style.css`,
    //     },
    //   ],
    // }),
  ],
})
